package com.cmc.cloud.cmclink.doc.api.document.req.so;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import java.util.ArrayList;
import java.util.List;

/**
 * 特种货审批flexi Base VO，提供给添加、修改、详细的子 VO 使用
 * 如果子 VO 存在差异的字段，请不要添加到这里，影响 Swagger 文档生成
 *
 * @author codegen
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SpecialCargoFlexiBaseVO {

    private Long id;

    @Schema(description = "箱型ID")
    private Long cntrId;

    @Schema(description = "包装的最大容量（升 L）")
    private Integer capacityOfFlexitank;

    @Schema(description = "液袋货的体积（升 L）")
    private Integer volumeOfCargo;

    @Schema(description = "液体最多能装多少比例")
    private Integer loadingRatio;

    @Schema(description = "货物描述", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 500, message = "货物描述支持最大长度{max}")
    private String cargoDescription;

    @Schema(description = "生产厂家", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 50, message = "生产厂家支持最大长度{max}")
    private String nameOfManufacturer;

    public void validate() {
        List<String> errors = new ArrayList<>();
        if (StringUtils.isEmpty(cargoDescription)) {
            errors.add("货物描述不能为空");
        }
        if (StringUtils.isEmpty(nameOfManufacturer)) {
            errors.add("生产厂家不能为空");
        }
        if (!errors.isEmpty()) {
            String join = String.join(",", errors);
        }
        if (null == capacityOfFlexitank) {
            capacityOfFlexitank = 0;
        }
        if (null == volumeOfCargo) {
            volumeOfCargo = 0;
        }
        if (null == loadingRatio) {
            loadingRatio = 0;
        }
    }

}
